package com.canaan.business.controller.pc.invoice;

import com.canaan.business.domain.invoice.WmsSalesOrderDetail;
import com.canaan.business.service.invoice.IWmsSalesOrderDetailService;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.core.page.TableDataInfo;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 单据明细Controller
 *
 * @author ruoyi
 * @date 2022-12-13
 */
@Api(tags = "单据明细管理")
@RestController
@RequestMapping("/invoice/salesOrderDetail")
public class WmsSalesOrderDetailController extends BaseController
{
    @Resource
    private IWmsSalesOrderDetailService wmsSalesOrderDetailService;

    /**
     * 查询单据明细列表
     */
    @ApiOperation(value = "查询单据明细列表")
    @GetMapping("/list")
    public TableDataInfo list(WmsSalesOrderDetail wmsSalesOrderDetail)
    {
        startPage();
        List<WmsSalesOrderDetail> list = wmsSalesOrderDetailService.selectWmsSalesOrderDetailList(wmsSalesOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出单据明细列表
     */
    @ApiOperation(value = "导出单据明细列表")
    @Log(title = "单据明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsSalesOrderDetail wmsSalesOrderDetail)
    {
        List<WmsSalesOrderDetail> list = wmsSalesOrderDetailService.selectWmsSalesOrderDetailList(wmsSalesOrderDetail);
        ExcelUtil<WmsSalesOrderDetail> util = new ExcelUtil<WmsSalesOrderDetail>(WmsSalesOrderDetail.class);
        util.exportExcel(response, list, "单据明细数据");
    }

    /**
     * 获取单据明细详细信息
     */
    @ApiOperation(value = "获取单据明细详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wmsSalesOrderDetailService.selectWmsSalesOrderDetailById(id));
    }

    /**
     * 新增单据明细
     */
    @ApiOperation(value = "新增单据明细")
    @Log(title = "单据明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsSalesOrderDetail wmsSalesOrderDetail)
    {
        return toAjax(wmsSalesOrderDetailService.insertWmsSalesOrderDetail(wmsSalesOrderDetail));
    }

    /**
     * 修改单据明细
     */
    @ApiOperation(value = "修改单据明细")
    @Log(title = "单据明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsSalesOrderDetail wmsSalesOrderDetail)
    {
        return toAjax(wmsSalesOrderDetailService.updateWmsSalesOrderDetail(wmsSalesOrderDetail));
    }

    /**
     * 删除单据明细
     */
    @ApiOperation(value = "删除单据明细")
    @Log(title = "单据明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsSalesOrderDetailService.deleteWmsSalesOrderDetailByIds(ids));
    }
}
